package taskmaster.job;

import taskmaster.job.Task;

/**taskmaster.job.TaskToChange
 *<BR><BR>
 *Used to show the details of a transformation change; used for the confirmation step to show info after a user's request to change the status of a task.
 *<BR><BR>
 *a simple wrapper class of Task that stores information about the change to status that the user requested.
 *Instances of this class are returned by the method call canMakeTransition() with an explanation of why this Task can't make the change toStatus, or null if it can.
 */
public class TaskToChange implements Comparable {
	
	/** the task to which the transition is to be made */
	public Task task = null;
	/** the status this task is going to */
	public int toStatus = -200;
	/** the reason why this task can't change from its current status to the status in toStatus */
	public String problem = null;
	
	/** Creates a new instance of TaskUnchangable */
	public TaskToChange(Task task, int toStatus, String problem) {
		this.task = task;
		this.toStatus = toStatus;
		this.problem = problem;
	}
	/** true if the reason this Task can't change to this toStatus is because the user only has read access */
	public boolean onlyHadRead() {
		return "onlyRead".equals(this.problem);
	}
	/** true if the reason this Task can't change to this toStatus is because the user needs admin access */
	public boolean neededAdmin() {
		return "needsAdmin".equals(this.problem);
	}
	/** true if the reason this Task can't change to this toStatus is because its not allowed in the tms.actions table */
	public boolean hadBadLogic() {
		return "brokenLogic".equals(this.problem);
	}
	/** true if this task can be changed to this status */
	public boolean canBeChanged() {
		return this.problem == null;
	}
	/** true if the reason this Task can't change to this toStatus is because its status has changed since the user decided to make this status */
	public boolean hasSyncError() {
		return "hasSyncError".equals(this.problem);
	}
	/** implements comparable interface so that an array of TaskToChange's can be sorted by the sort order defined by the stored Task object. */
	public int compareTo(Object o) {
		return task.compareTo(((TaskToChange)o).task);
	}
}
